package main

func longestConsecutive(nums []int) int {
	max := 0
	m := make(map[int]struct{})
	for i := 0; i < len(nums); i++ {
		m[nums[i]] = struct{}{}
	}

	for k, _ := range m {
		count := 1

		_, ok := m[k-1]
		if !ok {
			for {
				k++
				_, ok := m[k]
				if !ok {
					break
				}

				count++
			}
		}

		if count > max {
			max = count
		}

	}

	return max
}
